package com.upcontrol.uartagent.entity;

/**
 * Created by Administrator on 2017/2/15 0015.
 */

public class SNGetPacket extends UartPacket {
    private byte[] content;
    //    private String sn = "313031303130313032623336";
    public static final String SN_ERROR = "0000000000000000000000";
    private String sn = SN_ERROR;

    @Override
    public byte[] getContent() {
        return content;
    }

    @Override
    public void setContent(byte[] content) {
        sn = dumpHex(content);
        if (sn.length() != 24) {
            sn = SN_ERROR;
        }

        this.content = content;
    }

    /**
     * 获取机器人的上身板的SN
     *
     * @return 返回len=24的SN String， 如果返回全0，则获取出错，要做处理
     */
    public String getSN() {
        return sn;
    }

    public String dumpHex(byte[] src) {
        String num = "0123456789ABCDEF";
        StringBuilder sb = new StringBuilder();
        int len = src.length;
        for (byte aSrc : src) {
            int high = aSrc >> 4 & 0x0f;
            int low = aSrc & 0x0f;
//            System.out.print(num.charAt(high) + "" + num.charAt(low) + " ");
            sb.append(num.charAt(high)).append(num.charAt(low));
        }

        return sb.toString();
    }
}
